// 迁移梨享自动脚本代码
// Auth: hzp
// Time: 2019-12-17
package cron

import (
	"math"
	"time"
	"zimuzu_cvn_web_api/pkg/e"
	"zimuzu_cvn_web_api/service"
	"zimuzu_cvn_web_api/service/flows"
)

const YxFlowTask = "拉取网心流量"
const TwFlowTask = "拉取钛雾流量"
const YxMgNodeInfoTask = "网心结点信息"
const SubsidyForThirdRouterTask = "路由器补发"
const SupplyTokenPledgingCvnTask = "补充保证金"
const SuperMinerMiningCapacityTask = "统计收益能力"
const PaymentSuperTask = "超级结点结算"
const PaymentSuperFirstYearTask = "首年分红"
const StatisticalStageForYxTask = "结算统计"
const PaymentForRentUserTask = "租赁结算统计"
const PaymentForMgNodeTask = "结算发放"
const DailyBoardTask = "统计看板数据"
const DealOfflineTask = "处理离线任务"
const PaymentToProfitDetailTask = "结算完转收益明细"

// 更新每天节点数
func UpdateGlobalNodeNums() {

	var nodeF64, f, cvn float64
	nodeF64 = service.GetCurrentNode(1)
	f = e.PaymentFConstFVar * (math.Pow(nodeF64, e.PaymentFConstFPowVar))
	cvn = math.Min(f, 0.9906) * 30 * 0.9
	e.Log("info", "当前总质押节点：", nodeF64, "，今日结算节点：", nodeF64, "，代入公式f为：", f, "。预计低保为：", cvn)
	err := e.SendCronFSMS("18827097756", e.ParseString(nodeF64, 2), e.ParseString(nodeF64, 2), e.ParseString(f, 4), e.ParseString(cvn, 4))
	if err != nil {
		return
	}
	return
}

// 每天结算统计完再 计算租用令牌用户的收益能力 SuperMinerMiningCapacity
// Auth: hzp
func SuperMinerMiningCapacity() {

	err := service.GetSuperMinerMiningCapacity()
	service.MonitorSMS(SuperMinerMiningCapacityTask, err)
	return
}

// 网心流量接口 MgNodeFlows
// Auth: hzp
func MgNodeFlows() {

	err := service.GetMgNodeFlows()
	service.MonitorSMS(YxFlowTask, err)
	return
}

// 钛雾流量接口
// 每个小时第30分钟抓取前一个小时的流量数据
// Auth: hzp
func MgTwNodeFlows() {

	err := flows.GetTwLastDayFlow(time.Now().Hour(), "")
	service.MonitorSMS(TwFlowTask, err)
	return
}

// 网心结点信息 在线时长接口
// Auth: hzp
func MgNodeInfo() {

	err := service.GetMgNodeInfo()
	service.MonitorSMS(YxMgNodeInfoTask, err)
	return
}

// 每个月28号补发CVN
// Auth: hzp
func SubsidyPayment() {

	err := service.SubsidyForThirdRouter()
	service.MonitorSMS(SubsidyForThirdRouterTask, err)
	return
}

// 每天12点自动从余额补充到保证金
// Auth: hzp
func SupplyTokenPledgingCvn() {

	err := service.SupplyTokenPledgingCvn()
	service.MonitorSMS(SupplyTokenPledgingCvnTask, err)
	return
}

// 网心结算统计
// Auth: hzp
func StatisticalStage() {

	err := service.StatisticalStageForYx()
	service.MonitorSMS(StatisticalStageForYxTask, err)
	return
}

// 多线路结算统计
func MultipleStatisticalStage() {

	err := MultipleStatisticalProfit()
	service.MonitorSMS(StatisticalStageForYxTask, err)
	return
}

// 统计数据转收益明细
func MultiplePaymentToProfitDetail() {

	err := PaymentToProfitDetail("")
	service.MonitorSMS(PaymentToProfitDetailTask, err)
	return
}

// 结算给租用令牌用户统计
// Auth: hzp
func PaymentForRent() {

	err := service.PaymentForRentUser()
	service.MonitorSMS(PaymentForRentUserTask, err)
	return
}

// 结算发放
// Auth: hzp
func PaymentForMgNode() {

	err := service.PaymentForMgNode()
	service.MonitorSMS(PaymentForMgNodeTask, err)
	return
}

// 超级结点结算
// Auth: hzp
func PaymentSuper() {

	err := service.GrantForSuperNode()
	service.MonitorSMS(PaymentSuperTask, err)
	return
}

// 首年分红
// Auth: hzp
func PaymentSuperFirstYear() {

	err := service.GrantForSuperNode()
	service.MonitorSMS(PaymentSuperFirstYearTask, err)
	return
}

// 每天统计一份看板数据
// Auth: hzp
func AddDailyBoard() {

	err := flows.DailyBoard()
	service.MonitorSMS(DailyBoardTask, err)
	return
}

// 每天统计一份看板数据
// Auth: hzp
func DealOfflineNode() {

	err := flows.DealOfflineNode()
	service.MonitorSMS(DealOfflineTask, err)
	return
}
